﻿using System.Web.Mvc;
using ABC.Business.Models;
using ABC.Core.Configuration;
using ABC.Domain.Entities;

namespace ABC.Controllers
{
    
	public abstract class BaseController : Controller
	{
        private User currentUser;
        private readonly UserModel userModel;

        protected BaseController()
		{
			userModel = IoC.Resolve<UserModel>();
		}
        
        public User CurrentUser
        {
            get
            {
                if (currentUser == null && System.Web.HttpContext.Current.User != null && !string.IsNullOrEmpty(System.Web.HttpContext.Current.User.Identity.Name))
                {
                    currentUser = userModel.GetUser(System.Web.HttpContext.Current.User.Identity.Name);
                }
                
                return currentUser;
            }
        }
	}
}